﻿<%@ Page Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage" %>

<asp:Content ID="registerTitle" ContentPlaceHolderID="TitleContent" runat="server">
    Register
</asp:Content>

<asp:Content ID="registerContent" ContentPlaceHolderID="MainContent" runat="server">
    <h2>Create a New Account</h2>
    <p>
        Use the form below to create a new account. 
    </p>
    <p>
        Passwords are required to be a minimum of <%=Html.Encode(ViewData["PasswordLength"])%> characters in length.
    </p>
    <%= Html.ValidationSummary("Account creation was unsuccessful. Please correct the errors and try again.") %>

    <% using (Html.BeginForm()) { %>
        <div>
            <p>
                <label for="username">Username:</label>
                <%= Html.TextBox("username") %> <a href="#" rel="lnkCheckUserName">Check Username Availability</a> 
                <span id="loader"><img src="../../Content/Images/indicator.gif" alt="" style="vertical-align: text-top;" /></span> 
                <span id="usernamestatus"></span>
                <%= Html.ValidationMessage("username") %>                
            </p>
            <p>
                <label for="email">Email:</label>
                <%= Html.TextBox("email") %>
                <%= Html.ValidationMessage("email") %>
            </p>
            <p>
                <label for="password">Password:</label>
                <%= Html.Password("password") %>
                <%= Html.ValidationMessage("password") %>
            </p>
            <p>
                <label for="confirmPassword">Confirm password:</label>
                <%= Html.Password("confirmPassword") %>
                <%= Html.ValidationMessage("confirmPassword") %>
            </p>
            <p>
                <input type="submit" value="Register" />
            </p>
        </div>
    <% } %>
    <script type="text/javascript">
        $(document).ready(function() {
            $("#loader").hide();
            //check username js
            $("a[rel='lnkCheckUserName']").click(function(e) {
                e.preventDefault();
                var un = $("#username").val();
                if ($.trim(un).length <= 0) return;
                $("#loader").show();
                $.ajax({
                    type: "POST",
                    url: "/Account/IsUserExists",
                    data: "userName=" + escape(un),
                    dataType: "text",
                    success: function(data) {
                        if (data == "True") {
                            $("#usernamestatus").hide().html("Sorry, " + un + " is not available").removeClass().addClass("validation-summary-errors").show(300);
                        }
                        else {
                            $("#usernamestatus").hide().html("Yes, " + un + " is available").removeClass().addClass("success").show(300);
                        }
                        $("#loader").hide();
                    },
                    error: function(e, r, s) { $("#loader").hide();  alert(e + " - " + r + " - " + s); }
                });
            });
            $("#username").blur(function() {
                $("a[rel='lnkCheckUserName']").click();
            });
        });
    </script>
</asp:Content>
